/**
 *
 * Created by deng on 16-3-15.
 */

angular.module('metalabPartnerApp').controller('AchievementsCtrl', ['$scope', '$stateParams', '$state', '$anchorScroll', 'MetaResources', 'MetaRemind'
    , 'patent', 'paper', 'project'
    , function ($scope, $stateParams, $state, $anchorScroll, MetaResources, MetaRemind, patent, paper, project) {

        $scope.page = $stateParams.page;
        /**
         * 根据params
         */
        switch ($state.current.data.tag) {
            case '专利':
                $scope.achievementData = patent.data;
                $scope.achievementTotal = patent.headers['x-count'];
                break;
            case '论文':
                $scope.achievementData = paper.data;
                $scope.achievementTotal = paper.headers['x-count'];
                break;
            case '项目':
                $scope.achievementData = project.data;
                $scope.achievementTotal = project.headers['x-count'];
                break;
        }

        $scope.change = function () {
            $scope.waitingPromise=MetaResources.achievement.query({
                talentId: $stateParams.talentId,
                'tag': $state.current.data.tag,
                '_range': ($scope.page - 1) * 5 + 1 + '_' + ($scope.page) * 5
            }, function (data) {
                $scope.achievementData = data;
            }).$promise;
            $state.go('.', {page: $scope.page}, {notify: false});
            $anchorScroll('talent-sub');
            //$state.go('.', {page: $scope.page});
        };

    }]);
